﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SCS.Common.Models;
namespace SCS.DAL
{
    public class UnitOfWork : IUnitOfWork, IDisposable
    {
        private SCSContext DbContext { get; set; }

        /// <summary>
        /// Contructor
        /// </summary>
        public UnitOfWork()
        {
            DbContext = new SCSContext();
        }
        /// <summary>
        /// Contructor
        /// </summary>
        /// <param name="dbContext">DB Context</param>
        public UnitOfWork(SCSContext dbContext)
        {
            DbContext = dbContext;
        }

        /// <summary>
        /// Return context Unit of work
        /// </summary>
        /// <returns>DB context</returns>
        public SCSContext GetContext()
        {
            return DbContext;
        }

        /// <summary>
        /// Save Database
        /// </summary>
        public void Commit()
        {
            DbContext.SaveChanges();
        }

        /// <summary>
        /// Clear UnitOfWork
        /// </summary>
        public void Dispose()
        {
            DbContext.Dispose();
        }

        /// <summary>
        /// Repository for SchoolYear
        /// </summary>
        public IRepository<SchoolYear> SchoolYear
        {
            get
            {
                return new Repository<SchoolYear>(DbContext);
            }
        }

        /// <summary>
        /// Repository for Term
        /// </summary>
        public IRepository<Term> Term
        {
            get
            {
                return new Repository<Term>(DbContext);
            }
        }
        public IClassRepository Class
        {
            get
            {
                return new ClassRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for Learner
        /// </summary>
        public ILearnerRepository Learner
        {
            get
            {
                return new LearnerRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for Teacher
        /// </summary>
        public ITeacherRepository Teacher
        {
            get
            {
                return new TeacherRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for ClassInSchoolYear
        /// </summary>
        public IRepository<ClassInSchoolYear> ClassInSchoolYear
        {
            get
            {
                return new Repository<ClassInSchoolYear>(DbContext);
            }
        }

        /// <summary>
        /// Repository for Subject
        /// </summary>
        public IRepository<Subject> Subject
        {
            get
            {
                return new Repository<Subject>(DbContext);
            }
        }
        public IRepository<TeachingAssignment> TeachingAssignment
        {
            get
            {
                return new Repository<TeachingAssignment>(DbContext);
            }
        }

        /// <summary>
        /// Repository for Grade
        /// </summary>
        public IRepository<Grade> Grade
        {
            get
            {
                return new Repository<Grade>(DbContext);
            }
        }

        /// <summary>
        /// Repository for Comment
        /// </summary>
        public ICommentRepository Comment
        {
            get
            {
                return new CommentRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for GradeType
        /// </summary>
        public IRepository<GradeType> GradeType
        {
            get
            {
                return new Repository<GradeType>(DbContext);
            }
        }

        /// <summary>
        /// Repository for MembershipRole
        /// </summary>
        public IRepository<MembershipRole> MembershipRole
        {
            get
            {
                return new Repository<MembershipRole>(DbContext);
            }
        }

        /// <summary>
        /// Repository for MembershipUser
        /// </summary>
        public IMembershipRepository MembershipUser
        {
            get
            {
                return new MembershipRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for Parent
        /// </summary>
        public IParentRepository Parent
        {
            get
            {
                return new ParentRepository(DbContext);
            }
        }

        /// <summary>
        /// Repository for Parent
        /// </summary>
        public IParent2Repository Parent2
        {
            get
            {
                return new Parent2Repository(DbContext);
            }
        }

        /// <summary>
        /// Repository for Teacher to View
        /// </summary>
        public IRepository<Parent> ParentViewTeacher
        {
            get
            {
                return new Repository<Parent>(DbContext);
            }
        }

        /// <summary>
        /// Repository for Private Message
        /// </summary>
        public IPrivateMessageRepository PrivateMessage
        {
            get
            {
                return new PrivateMessageRepository(DbContext);
            }
        }
    }
}
